<link rel="stylesheet" href="/sources/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="/sources/layui/css/layuimini.css" media="all" />
<script type="text/javascript" src="/sources/layui/layui.js"></script>
<script type="text/javascript" src="/sources/layui/layui.js?v=1.0.4" charset="utf-8"></script>


<div class="layui-fluid">
  <div class="layui-card" style="margin: 15px 0;">

    <div class="layui-card-body">
      <div style="padding-bottom: 10px;right: 0;">
        <button class="layui-btn data-add-btn" data-type="add">新增解决方案</button>
      </div>

      <table class="layui-table" id="solution" lay-filter="solution"></table>
      <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
      </script>

    </div>
  </div>
</div>

<script>
  layui.use([ 'element', 'table', 'layer', 'laytpl', 'form'], function () {
    var element = layui.element,
      table = layui.table,
      view = layui.view,
      form = layui.form,
      $ = layui.$;

    form.render();

    table.render({
      elem: '#solution',
      url: 'http://124.133.35.234:8000/solution/getsolutionlist',
      // data: [{
      //   id: 0,
      //   name: 1
      // }],
      method: "POST",
      title: '巡检地点表',
      totalRow: true,
      cellMinWidth: 100,
      limits: [10, 20, 30, 40, 50],
      limit: 10,
      page: true,
      cols: [[
        { field: 'id', title: '序号', width: 69, fixed: true, templet: '<div>{{d.LAY_TABLE_INDEX+1}}</div>' },
        { field: 'area', width: 200, title: '编码' },
        { field: 'area', title: '标题'},
        { field: 'area', title: '行业' },
        { field: 'area', title: '图片名称' },
        { field: 'area', title: '文件名称' },
        { field: 'area', title: '下载次数'},
        { field: 'area', title: '单位' },
        { field: 'name', title: '联系电话' },
        { field: 'name', title: '邮箱' },
        { field: 'name', title: '创建人'},
        { field: 'name', title: '创建时间' },
        { field: 'name', title: '描述' },
        { width: 200, fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo' }
      ]],
    })

    //添加
		var active = {
			add: function () {
        location.href = 'add.html';
			}
		};

		$('.data-add-btn').on('click', function () {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

    //监听工具条
    table.on('tool(solution)', function(obj){
      var data = obj.data;
      console.log(data);
      if(obj.event === 'edit'){ // 修改
        // admin.popup({
				// 	title: '修改巡检地点',
				// 	area: ['50%', '80%'],
				// 	id: 'LAY-popup-place-edit',
				// 	success: function (layero, index) {
				// 		view(this.id).render('siteInspection/place/edit', data).done(function () {
				// 			form.render();
				// 		});
				// 	}
				// });
      } else if(obj.event === 'del'){ // 删除
        layer.confirm('是否删除该行', function(index){
          $.ajax({
						// url: layui.setter.http + '/mine/inspection/delete',
						type: 'post',
						dataType: 'json',
						data: { id: data.id },
						success: function (data) {
							obj.del();
							layer.close(index);
							layer.msg('删除成功');
						}
					})
        });
      }
    });

  });
</script>








